package com.lfz.quality_effect.controller;


import com.lfz.quality_effect.exception.MyException;
import com.lfz.quality_effect.model.dto.TimeDTO;
import com.lfz.quality_effect.model.vo.EleScoreRankVO;
import com.lfz.quality_effect.model.vo.ScoreRankVO;
import com.lfz.quality_effect.service.TCollectionBalanceCopyService;
import com.lfz.quality_effect.utils.ResultData;
import com.lfz.quality_effect.utils.ReturnCode;
import com.lfz.quality_effect.utils.TimeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

@Api(tags = "综合报表平台数据源",value = "TCollectionBalanceCopyController")
@RestController
@RequestMapping("/api/collectionBalanceCopy")
public class TCollectionBalanceCopyController {


    @Autowired
    private TCollectionBalanceCopyService tCollectionBalanceCopyService;


    @ApiOperation("上传全省优化营商环境主要监测指标总表")
    @PostMapping("/uploadCivilSettledRate")
    public ResultData uploadCivilSettledRate(@RequestParam("file") MultipartFile file, String dataTime){

        if (StringUtils.isEmpty(dataTime)){
            throw new MyException(ReturnCode.RC10001.getCode(),ReturnCode.RC10001.getMsg());
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            dataTime = simpleDateFormat.format(TimeUtils.vertifyTime(dataTime));
        }catch (Exception e){
            throw new MyException(ReturnCode.RC10002.getCode(),ReturnCode.RC10002.getMsg());
        }
        tCollectionBalanceCopyService.uploadCivilSettledRate(file,dataTime);
        return ResultData.ok();
    }


    @ApiOperation("上传全省质效详表")
    @PostMapping("/uploadTotalSettledRate")
    public ResultData uploadTotalSettledRate(@RequestParam("file") MultipartFile file, String dataTime){

        if (StringUtils.isEmpty(dataTime)){
            throw new MyException(ReturnCode.RC10001.getCode(),ReturnCode.RC10001.getMsg());
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            dataTime = simpleDateFormat.format(TimeUtils.vertifyTime(dataTime));
        }catch (Exception e){
            throw new MyException(ReturnCode.RC10002.getCode(),ReturnCode.RC10002.getMsg());
        }
        tCollectionBalanceCopyService.uploadTotalSettledRate(file,dataTime);
        return ResultData.ok();
    }


    @ApiOperation("获取民商事结案率排名")
    @PostMapping(value = "/getCivilSettledRateRank")
    public ResultData<List<ScoreRankVO>> getCivilSettledRateRank(){
        List<ScoreRankVO> scoreRankVOList = tCollectionBalanceCopyService.getCivilSettledRateRank();
        return ResultData.ok().data(scoreRankVOList);
    }

    @ApiOperation("获取总结案率排名")
    @PostMapping(value = "/getTotalSettledRateRank")
    public ResultData<List<ScoreRankVO>> getTotalSettledRateRank(){
        List<ScoreRankVO> scoreRankVOList = tCollectionBalanceCopyService.getTotalSettledRateRank();
        return ResultData.ok().data(scoreRankVOList);
    }

    @ApiOperation("获取民商事结案率趋势图")
    @GetMapping(value = "/getCivilSettledRateRankTrend")
    public ResultData<List<ScoreRankVO>> getCivilSettledRateRankTrend(@RequestParam("startTime") String startTime,@RequestParam("endTime") String endTime){
        Map<String,List<EleScoreRankVO>> scoreRankVOList = tCollectionBalanceCopyService.getCivilSettledRateRankTrend(startTime,endTime);
        return ResultData.ok().data(scoreRankVOList);
    }

    @ApiOperation("获取总结案率趋势图")
    @GetMapping(value = "/getTotalSettledRateRankTrend")
    public ResultData<List<ScoreRankVO>> getTotalSettledRateRankTrend(@RequestParam("startTime") String startTime,@RequestParam("endTime") String endTime){
        Map<String,List<EleScoreRankVO>> scoreRankVOList = tCollectionBalanceCopyService.getTotalSettledRateRankTrend(startTime,endTime);
        return ResultData.ok().data(scoreRankVOList);
    }

    //    @ApiOperation("获取民商事结案率趋势图")
//    @PostMapping(value = "/getCivilSettledRateRankTrend")
//    public ResultData<List<ScoreRankVO>> getCivilSettledRateRankTrend(@RequestBody TimeDTO timeDTO){
//        String startTime = timeDTO.getStartTime();
//        String endTime = timeDTO.getEndTime();
//        Map<String,List<EleScoreRankVO>> scoreRankVOList = tCollectionBalanceCopyService.getCivilSettledRateRankTrend(startTime,endTime);
//        return ResultData.ok().data(scoreRankVOList);
//    }


//    @ApiOperation("获取总结案率趋势图")
//    @PostMapping(value = "/getTotalSettledRateRankTrend")
//    public ResultData<List<ScoreRankVO>> getTotalSettledRateRankTrend(@RequestBody TimeDTO timeDTO){
//        String startTime = timeDTO.getStartTime();
//        String endTime = timeDTO.getEndTime();
//        Map<String,List<EleScoreRankVO>> scoreRankVOList = tCollectionBalanceCopyService.getTotalSettledRateRankTrend(startTime,endTime);
//        return ResultData.ok().data(scoreRankVOList);

//    }

}
